package ru.efimmatytsin.tweeterella.converters;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import ru.efimmatytsin.tweeterella.entities.User;
import ru.efimmatytsin.tweeterella.viewmodels.UserViewModel;

/**
 * Created by Efim Matytsin on 22.02.15.
 */
@Component
public class UserViewModelConverter implements Converter<User,UserViewModel> {

    @Autowired
    private PhotoViewModelConverter converter;
    @Override
    public UserViewModel convert(User user) {
        if(user == null){
            return null;
        }
        UserViewModel userViewModel = new UserViewModel();
        userViewModel.setFirstName(user.getFirstName());
        userViewModel.setLastName(user.getLastName());
        userViewModel.setEmail(user.getEmail());
        userViewModel.setUsername(user.getUsername());
        userViewModel.setPhoto(converter.convert(user.getPhoto()));
        return userViewModel;
    }
}
